package com.lanren.common.widget.statusbar;

import android.content.Context;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.View;

import com.lanren.common.widget.statusbar.StatusBarUtil;

/**
 * @ClassName StatusBar
 * @Description TODO 沉浸式时状态栏高度设置
 * @Author chongheng.wang
 * @Date 2019/9/2 14:10
 * @Version 1.0
 */
public class StatusBar extends View {
    private int height;

    public StatusBar(Context context) {
        this(context, null);
    }

    public StatusBar(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        if (isInEditMode()) {
            height = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 24, getResources().getDisplayMetrics());
        } else {
            height = StatusBarUtil.getStatusBarHeight(context);
            if (height == 0) {
                setVisibility(GONE);
            }
        }
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        final int width = MeasureSpec.getSize(widthMeasureSpec);
        setMeasuredDimension(width, height);
    }
}
